from fastapi import APIRouter, Depends, Request
from module_admin.service.login_service import LoginService
from module_admin.entity.vo.attendance_vo import AttendanceModel, AttendanceQueryModel
from typing import List
# 权限
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from sqlalchemy.ext.asyncio import AsyncSession
from config.get_db import get_db
from module_admin.aspect.data_scope import GetDataScope
from module_admin.service.attendance_service import AttendanceService
from utils.log_util import logger
from utils.response_util import ResponseUtil
from pydantic_validation_decorator import ValidateFields
from module_admin.annotation.log_annotation import Log
from config.enums import BusinessType
from datetime import datetime


# attendance考勤管理-路由-实现
attendanceController = APIRouter(prefix='/system/attendance', dependencies=[Depends(LoginService.get_current_user)])

@attendanceController.get('/list', response_model=List[AttendanceModel], dependencies=[Depends(CheckUserInterfaceAuth('system:attendance:list'))]
)
# 考勤查询模型，使用 Depends 依赖注入系统自动处理查询参数；
# AttendanceQueryModel.as_query 来自module_admin/annotation/pydantic_annotation.py；这个装饰器的主要作用是将 Pydantic 模型转换为 FastAPI 的查询参数；
async def get_system_attendance_list(
    request: Request,
    attendance_query: AttendanceQueryModel = Depends(AttendanceQueryModel.as_query), # 将 Pydantic 模型转换为 FastAPI 的查询参数；
    query_db: AsyncSession = Depends(get_db), # 数据库连接
    data_scope_sql: str = Depends(GetDataScope('AttendanceInfo')), # 获取当前用户数据权限对应的查询sql语句
):
    attendance_query_result = await AttendanceService.get_attendance_list_services(query_db, attendance_query, data_scope_sql, is_page=True)
    logger.info('获取成功')

    return ResponseUtil.success(model_content=attendance_query_result)

